<?php

namespace App\Orchid\Layouts\Category;

use App\Models\Category;
use Orchid\Filters\Filter;
use Orchid\Screen\Field;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Fields\Select;
use Orchid\Screen\Layouts\Rows;

class CategoryFiltersLayout extends Rows
{
    /**
     * Used to create the title of a group of form elements.
     *
     * @var string|null
     */
    protected $title = '筛选器';

    /**
     * Get the fields elements to be displayed.
     *
     * @return Field[]
     */
    protected function fields(): iterable
    {
        return [
            Input::make('filter[name]')
                ->type('text')
                ->value($this->query->get('filter.name'))
                ->placeholder('按分类名称搜索')
                ->title('分类名称'),

            Select::make('filter[parent_id]')
                ->fromModel(Category::class, 'name')
                ->empty('所有父分类')
                ->value($this->query->get('filter.parent_id'))
                ->title('父分类'),

            Input::make('filter[slug]')
                ->type('text')
                ->value($this->query->get('filter.slug'))
                ->placeholder('按Slug搜索')
                ->title('Slug'),
        ];
    }
}